import Axios from 'axios/index';
import {message} from "gov-design-vue";

//const baseUrl = "http://127.0.0.1:8080/crux-cisupport";

const baseUrl = "/crux-cisupport";

export function fetch(url, method, data) {
  let that = this;
  return Axios.request({
    url: url,
    method: method,
    baseURL: baseUrl,
    headers: {
      'X-Requested-With': 'XMLHttpRequest',
      "Content-Type": "application/json"
    },
    data: data
  }).catch((reason) => {
    if (reason.response && reason.response.data) {
      //that.$message.error(reason.response.data.msg);
      message.error(reason.response.data.msg);
      console.log(reason.response.data.extMsg.ex);
    } else {
      //that.$message.error(reason);
      message.error(reason);
    }
  });
}

export function getFetch(url) {
  return fetch(url, "GET");
}

export function postFetch(url, data) {
  return fetch(url, "POST", data);
}

export function getBaseUrl() {
  return baseUrl;
}
